file(GLOB DRIVER_HAL_SOURCES
    ${PROJ_DRIVERS_DIR}/STM32F1xx_HAL_Driver/Src/Legacy/*hal*.c
    ${PROJ_DRIVERS_DIR}/STM32F1xx_HAL_Driver/Src/*hal*.c
)

file(GLOB DRIVER_LL_SOURCES
    ${PROJ_DRIVERS_DIR}/STM32F1xx_HAL_Driver/Src/Legacy/*ll*.c
    ${PROJ_DRIVERS_DIR}/STM32F1xx_HAL_Driver/Src/*ll*.c
)

file(GLOB DRIVER_CMSIS_SOURCES
    ${PROJ_DRIVERS_DIR}/CMSIS/system_stm32f1xx.c
)

if(USE_LL_LIB)
    set(DRIVER_SOURCES ${DRIVER_SOURCES} ${DRIVER_LL_SOURCES} ${DRIVER_CMSIS_SOURCES})
endif()

if(USE_HAL_LIB)
    set(DRIVER_SOURCES ${DRIVER_SOURCES} ${DRIVER_HAL_SOURCES} ${DRIVER_CMSIS_SOURCES})
endif()



set(DRIVER_HEADERS
    ${PROJ_DRIVERS_DIR}/STM32F1xx_HAL_Driver/Inc/Legacy
    ${PROJ_DRIVERS_DIR}/STM32F1xx_HAL_Driver/Inc
    ${PROJ_DRIVERS_DIR}/CMSIS/Include
)

message(STATUS "Driver Source: ${DRIVER_SOURCES}")
message(STATUS "Driver Header: ${DRIVER_HEADERS}")

add_library(drivers
    ${DRIVER_SOURCES}
)

target_include_directories(drivers PUBLIC
    ${DRIVER_HEADERS}
)

if(USE_LL_LIB)
    target_compile_definitions(drivers PUBLIC USE_FULL_LL_DRIVER __CHECK_DEVICE_DEFINES)
endif()